/* Copyright (C) 2008 Nick Crafford <nickcrafford@earthlink.net>
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

var image = /[jpg|gif|png|jpeg|JPG|GIF|PNG|JPEG]/;

function gameBoard(left, top, numWide, numHigh, spaceWidth, spaceHeight, spaceColor, bgColor) {

    this.left             = left;
    this.top              = top;
    this.numWide          = numWide;
    this.numHigh          = numHigh;
    this.spaceWidth       = spaceWidth;
    this.spaceHeight      = spaceHeight;
    this.spaceColor       = spaceColor;
    this.bgColor          = bgColor;
    this.gameOver         = false;
    this.playerWon        = 0;
    this.lockedPlayer     = 0;
    this.gameSlots        = new Array();
    this.gamePieces       = new Array();
    this.illegalGameSlots = new Array();
    this.width            = this.numWide*this.spaceWidth;
    this.height           = this.numHigh*this.spaceHeight;
    this.gameOn           = true;

    var moves = new Array();  //X,Y combos of moves taken by player1
    var s     = new Object(); //Sound layer 1 Object
    var s2    = new Object(); //Sound layer 2 Object

    /*
     addGP()     - void        - Add a gamepiece to this board object.
     cpu         - boolean     - Is this a piece controlled by the computer?
     gs          - gameGraphic - The graphic that occupies the space on this board that you want to put this gamepiece on.
     gg          - gameGraphic - The graphic that is the new gamePiece.
     centerPiece - boolean     - Do you want the piece centered in the slot gs?
     playerNum   - int         - Assign a number to this player so we know who's pieces are whos.
     flippedDown - boolean     - Is this piece showing its rank?
    */
    this.addGP = function(cpu, gs, gg,rank, centerPiece, playerNum,flippedDown) {
        gg.x           = gs.x;
        gg.y           = gs.y;
        gg.type        = 'piece';
        gg.playerNum   = playerNum;
        gg.flippedDown = flippedDown;
        gg.cpu         = cpu;

        gg.setRank(rank);

        //Don't add a piece to a slot that has been marked as disabled!
        if(gs.enabled)
        {
            if(centerPiece)
            {
                gg.left = this.left+(gs.x*this.spaceWidth)+(gg.length/2);
                gg.top  = this.top+(gs.y*this.spaceHeight)+(gg.height/2);
            }

            //When the piece is clicked, this function will be called.
            gg.setClickCallback('boardclicked');
            this.gamePieces.push(gg);
            gg.paint('');
        }
    }

    /*
    setIllegalSlot() - void - mark a slot on this board object as illegal (Not able to add a game piece to).
    x                - int  - X coordinate on the board of the slot you want to make illegal.
    y                - int  - Y coordinate on the board of the slot you want to make illegal.
    */
    this.setIllegalSlot = function(x,y) {
        for(var i=0; i <  this.gameSlots.length; i++)
        {
            tGG = this.gameSlots[i];

            if(x == tGG.x && y == tGG.y)
                this.gameSlots[i].enabled = false;
        }
    }

    /*
     getSlot() - void - Supply the id property of a gameGraphic Object that has been assinged as a slot and get back the object.
     id        - int  - id of the gameGraphic object assigned as a slot.
    */
    this.getSlot = function(id) {
        var fSlot = new Object();
        var tSlot = new Object();

        for(var r=0; r < this.gameSlots.length; r++)
        {
            tSlot = this.gameSlots[r];

            if(tSlot.idNumber == id)
                fSlot = this.gameSlots[r];
        }

        return fSlot;
    }

    /*
     popPiece() - void        - Remove a gameGraphic object from the gamePieces array that contains all active pieces on the board.
     gp         - gameGraphic - A game graphic object assigned as a piece.
    */
    this.popPiece = function(gp) {
        var tArr = Array();

        for(var i=0; i < this.gamePieces.length; i++)
        {
            tP = this.gamePieces[i];

            if(tP.idNumber != gp.idNumber)
                tArr.push(tP);
        }

        this.gamePieces = tArr;
    }

    this.getSlotXY = function(x,y) {
        var fSlot = new Object();
        var tSlot = new Object();

        for(var r=0; r < this.gameSlots.length; r++)
        {
            tSlot = this.gameSlots[r];

            if(tSlot.x == x && tSlot.y == y)
                fSlot = this.gameSlots[r];
        }

        return fSlot;
    }

    this.getPiece = function(id) {
        var fPiece = new Object();
        var tPiece = new Object();

        for(var r=0; r < this.gamePieces.length; r++)
        {
            tPiece = this.gamePieces[r];

            if(tPiece.idNumber == id)
                fPiece = this.gamePieces[r];
        }

        return fPiece;
    }

    this.getPieceOrSlot = function(id) {
         var fPiece = new Object();

        for(var a=0; a < this.gamePieces.length; a++)
        {
            tPiece = this.gamePieces[a];
            if(tPiece.idNumber == id)
                fPiece = this.gamePieces[a];
        }

        for(var b=0; b < this.gameSlots.length; b++)
        {
            tSlot = this.gameSlots[b];
            if(tSlot.idNumber == id)
                fPiece = this.gameSlots[b];
        }

        return fPiece;
    }

    this.getPieceOrSlotXY = function(x,y) {
         var fPiece    = new Object();
         var tPiece    = new Object();
         var tSlot     = new Object();
         var foundSlot = false;

        for(var b=0; b < this.gameSlots.length; b++)
        {
            tSlot = this.gameSlots[b];

            if(tSlot.x == x && tSlot.y == y)
                fPiece = this.gameSlots[b];
        }

        for(var a=0; a < this.gamePieces.length; a++)
        {
            tPiece = this.gamePieces[a];

            if(tPiece.x == x && tPiece.y == y)
                fPiece = this.gamePieces[a];
        }

        return fPiece;
    }


    this.getPieceXY = function(x,y) {
        var fPiece = new Object();
        var tPiece = new Object();

        for(var r=0; r < this.gamePieces.length; r++)
        {
            tPiece = this.gamePieces[r];

            if(tPiece.x == x && tPiece.y == y)
                fPiece = this.gamePieces[r];
        }

        return fPiece;
    }


    this.removeGP = function(x,y) {

    }

    this.setAllPiecesOpac = function() {
        for(var i=0; i < this.gamePieces.length; i++)
        {
            this.gamePieces[i].changeOpacity(1);
        }
    }

    this.playerHasMoved = function(iGG)
    {
        this.lockedPlayer = iGG.playerNum;
        this.randomMove(2);
    }

    this.moveGP = function(gp,x,y) {

        if(!this.gameOn)return false;

        //alert(gp.type);
        var moveTo    = this.getSlotXY(x,y); //Get Slot that we are moving into
        var xDiff     = x - gp.x;
        var yDiff     = y - gp.y;
        var axDiff    = Math.abs(xDiff);
        var ayDiff    = Math.abs(yDiff);


        //alert(x + '-' + gp.x + '  ' + xDiff+'::abs('+Math.abs(xDiff)+') , ' + y + '-' + gp.y + '  ' + yDiff+'::abs('+Math.abs(yDiff)+')');

        //Check Valid directions for movement
        var movingEast      = xDiff > 0  && gp.east;  //&& (axDiff <= gp.eastMoves);
        var movingWest      = xDiff < 0  && gp.west;  //&& (axDiff <= gp.westMoves);
        var movingNorth     = yDiff < 0  && gp.north; //&& (ayDiff <= gp.northMoves);
        var movingSouth     = yDiff > 0  && gp.south; //&& ();
        var movingNorthEast = movingEast && movingNorth;
        var movingNorthWest = movingWest && movingNorth;
        var movingSouthEast = movingEast && movingSouth;
        var movingSouthWest = movingWest && movingSouth;
        var southMovesOk    = ayDiff <= gp.southMoves;
        var northMovesOk    = ayDiff <= gp.northMoves;
        var westMovesOk     = axDiff <= gp.westMoves;
        var eastMovesOk     = axDiff <= gp.eastMoves;
        var samePlayer      = false;
        var maxRepeatMoves  = 3;


        var pieceNotMovingOntoTeamate     = true;
        var pieceNotJumpingIllegalSlot    = true;
        var pieceNotOverRepeatThreshold   = true;
        var pieceNotMovingOntoIllegalSlot = true;
        var piecesMovementWithinRange     = false;

        var validMove                     = false;
        var doMove                        = false;

        var offenseWins = false;
        var defenseWins = false;

        var flipColor = '';

        var deadPiece                     = new Object();

        //alert('movingEast='+movingEast+'. ' + 'movingWest='+movingWest+'. ' + 'movingNorth='+movingNorth+'. movingSouth='+movingSouth);

        if((movingEast  ||
            movingWest  ||
            movingNorth ||
            movingSouth) &&
           (southMovesOk &&
            northMovesOk &&
            westMovesOk  &&
            eastMovesOk) &&
           (!movingNorthEast &&
            !movingNorthWest &&
            !movingSouthEast &&
            !movingSouthWest)&&
           moveTo.enabled &&
           gp.playerNum != this.lockedPlayer
          )
        {
            piecesMovementWithinRange = true;
        }

        //Make sure pieces don't try to jump over an illegal slot
        for(var a=0; a < this.gameSlots.length; a++)
        {
            tSlot = this.gameSlots[a];

            if(!tSlot.enabled)
            {
                //alert(tSlot.x+','+tSlot.y);
                if((gp.x < tSlot.x && y == tSlot.y && x > tSlot.x) ||
                    (gp.x > tSlot.x && y == tSlot.y && x < tSlot.x) ||
                    (gp.y < tSlot.y && x == tSlot.x && y > tSlot.y) ||
                    (gp.y > tSlot.y && x == tSlot.x && y < tSlot.y))
                {
                    //Piece is trying to jump over an illegal slot!!
                    pieceNotMovingOntoIllegalSlot = false;
                }
            }
        }

        //Make sure slot moving to is valid
        //Make sure piece isn't trying to move over/ontop of another piece
        //Handle Combat
        for(var a=0; a < this.gamePieces.length; a++)
        {
            tPiece = this.gamePieces[a];

            if((gp.x < tPiece.x && y == tPiece.y && x > tPiece.x) ||
                (gp.y < tPiece.y && x == tPiece.x && y > tPiece.y))
            {
                //Piece is trying to jump over an illegal slot!!
                pieceNotJumpingIllegalSlot = false;
            }

            if(tPiece.x == x && tPiece.y == y && tPiece.idNumber != gp.idNumber)
            {
                if(tPiece.playerNum != gp.playerNum)
                {
                    if(gp.playerNum == 2 && gp.flippedDown)
                    {
                        flipColor = 'gfx/animated/b'+gp.rank + '.gif';
                    }
                    else if(gp.playerNum == 1  && gp.flippedDown)
                    {
                        flipColor = 'gfx/animated/r'+gp.rank + '.gif';
                    }

                    if(tPiece.rank == 'F')
                    {
                        this.gameOver = true;
                        this.playerWon = gp.playerNum;
                        this.attachSound('sound/comp.wav');
                        alert('You found the flag!!');
                        this.flipPieces(true);
                        this.gameOn = false;
                    }
                    else
                    {
                        if(gp.rank == 9)
                        {
                            alert('Player ' + tPiece.playerNum + ' scouts piece. Rank = ' + tPiece.rank);
                        }

                        //Compare Rank of pieces
                        //alert(gp.rank + '::'+ tPiece.rank);

                        if((gp.rank <= tPiece.rank && tPiece.rank != 'S' && tPiece.rank != 'B') ||
                           (gp.rank == 'S' && tPiece.rank == 1) ||
                           (gp.rank == 8 && tPiece.rank == 'B') ||
                           (tPiece.rank == 'S'))
                        {
                            offenseWins = true;
                            deadPiece = tPiece;
                        }
                        else
                        {
                            defenseWins = true;
                        }
                    }
                }
                else
                {
                    pieceNotMovingOntoTeamate = false;
                }
            }
        }

        validMove = pieceNotMovingOntoTeamate     &&
                    pieceNotJumpingIllegalSlot    &&
                    pieceNotMovingOntoIllegalSlot &&
                    piecesMovementWithinRange;

        if(!gp.cpu && validMove)
        {
            moves.push(x+','+y);

            if(moves.length == (maxRepeatMoves*2-1))
            {
                var uTally = 0;
                var dTally = 0;
                var uMove  = moves[0];
                var dMove  = moves[1];

                for(var z=0; z < moves.length; z++)
                {
                    if(uMove == moves[z])
                        uTally++;
                    else if(dMove == moves[z])
                        dTally++;
                }

                moves = new Array();

                if(uTally == maxRepeatMoves && dTally == maxRepeatMoves-1)
                {
                    pieceNotOverRepeatThreshold = false;
                }
            }
        }

        if(validMove && pieceNotOverRepeatThreshold)
        {
            if(flipColor == '')
            {
                    if(gp.playerNum == 2)
                    {
                        flipColor = 'gfx/b.gif';
                    }
                    else if(gp.playerNum == 1)
                    {
                        flipColor =  'gfx/r'+gp.rank + '.gif';
                    }
            }

            if(offenseWins)
            {
                deadPiece.erase();

                this.popPiece(deadPiece);

                doMove = true;

                this.attachSound('sound/scream.wav');
            }
            else if(defenseWins)
            {
                gp.erase();

                this.popPiece(gp);

                this.attachSound('sound/scream.wav');
            }
            else
            {
                doMove = true;

            }

            if(doMove)
            {
                gp.x = x;
                gp.y = y;

                gp.left = this.left + (x*this.spaceWidth) + (gp.length/2);
                gp.top  = this.top + (y*this.spaceHeight) + (gp.height/2);

                gp.erase();
                gp.paint(flipColor);
            }
        }
        else if(!pieceNotOverRepeatThreshold)
        {
            gp.erase();

            this.popPiece(gp);

            this.attachSound('sound/scream.wav');
        }

        return validMove;
    }

    this.flipPieces = function(lock) {
        for(var i=0; i < this.gamePieces.length; i++) {
            gp = this.gamePieces[i];
            if(lock)gp.setClickCallback('');
            gp.erase();
            gp.paint('gfx/'+(gp.playerNum==1?'r':'b')+''+gp.rank+'.gif');
        }
    }

    //Very Important for the CPU Player
    //This could be the place to put actual AI later on :)
    this.randomMove = function(playerNum)
    {
        var pPieces = new Array();
        var pX      = new Array();
        var pY      = new Array();
        var tPiece = new Object();

        for(var i=0; i < this.gamePieces.length; i++)
        {
            tPiece = this.gamePieces[i];

            //Piece is movable and belongs to the correct player
            if(tPiece.playerNum == playerNum && tPiece.rank != 'B' && tPiece.rank != 'F')
            {
                //Does the piece have any empty ajacent slots?
                //Are the slots legal moves?

                for(var e = 1; e <= tPiece.eastMoves && e >= 0; e++)
                {
                    var gg = this.getPieceOrSlotXY(tPiece.x-e,tPiece.y);

                    if(gg.type == 'slot' && gg.enabled)
                    {
                        //alert('Good Slot='+gg.x+','+gg.y);
                        //pMoves.push(new Move(tPiece, gg.x, gg.y));
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                    }
                    else if(gg.type == 'piece' && gg.playerNum != playerNum)
                    {
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                        break;
                    }
                    else if(gg.type == 'piece' && gg.playerNum == playerNum || gg.type == 'slot' && !gg.enabled)
                    {
                        break;
                    }
                }

                for(var w = 1; w <= tPiece.westMoves && w <= 9; w++)
                {
                    var gg = this.getPieceOrSlotXY(tPiece.x+w,tPiece.y);

                    if(gg.type == 'slot' && gg.enabled)
                    {
                        //alert('Good Slot='+gg.x+','+gg.y);
                        //pMoves.push(new Move(tPiece, gg.x, gg.y));
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                    }
                    else if(gg.type == 'piece' && gg.playerNum != playerNum)
                    {
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                        break;
                    }
                    else if(gg.type == 'piece' && gg.playerNum == playerNum || gg.type == 'slot' && !gg.enabled)
                    {
                        break;
                    }
                }


                for(var n = 1; n <= tPiece.northMoves && n >=0; n++)
                {
                    var gg = this.getPieceOrSlotXY(tPiece.x,tPiece.y-n);

                    if(gg.type == 'slot' && gg.enabled)
                    {
                        //alert('Good Slot='+gg.x+','+gg.y);
                        //pMoves.push(new Move(tPiece, gg.x, gg.y));
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                    }
                    else if(gg.type == 'piece' && gg.playerNum != playerNum)
                    {
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                        break;
                    }
                    else if(gg.type == 'piece' && gg.playerNum == playerNum || gg.type == 'slot' && !gg.enabled)
                    {
                        break;
                    }
                }


                for(var s = 1; s <= tPiece.southMoves && s <= 9; s++)
                {
                    var gg = this.getPieceOrSlotXY(tPiece.x,tPiece.y+s);

                    if(gg.type == 'slot' && gg.enabled)
                    {
                        //alert('Good Slot='+gg.x+','+gg.y);
                        //pMoves.push(new Move(tPiece, gg.x, gg.y));
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                    }
                    else if(gg.type == 'piece' && gg.playerNum != playerNum)
                    {
                        pPieces.push(tPiece);
                        pX.push(gg.x);
                        pY.push(gg.y);
                        break;
                    }
                    else if(gg.type == 'piece' && gg.playerNum == playerNum || gg.type == 'slot' && !gg.enabled)
                    {
                        break;
                    }
                }
            }
        }

        //alert(pMoves.length);

        var seed = Math.floor(Math.random()*pPieces.length);

        //alert(seed);
        //var tMove = pPieces[seed];
        this.attachSound('sound/electric.wav');
        this.moveGP(pPieces[seed], pX[seed], pY[seed]);

        this.lockedPlayer = 0;

    }

    this.hasMove = function(tp)
    {
    }

    this.slotContainsGP = function(x,y) {
        var r = false;

        for(var i=0; i <  this.gamePieces.length; i++)
        {
            tGP = this.gamePieces[i];

            if(x == tGP.x && y == tGP.y)
            {
                r = true;
            }
        }

        return r;
    }

    this.paint = function() {
        var tImg = window.document.createElement('img');

        var styleString = 'position:absolute;left:'+this.left+';top:'+this.top+';';

        tImg.setAttribute('style',styleString);
        tImg.setAttribute('src',this.bgColor);

        document.body.appendChild(tImg);

        for(var x=0; x < this.numWide; x++)
        {
            for(var y=0; y < this.numHigh; y++)
            {
                gg = new gameGraphic(this.spaceHeight,
                                     this.spaceWidth,
                                     this.left+(this.spaceWidth*x),
                                     this.top+(this.spaceHeight*y),
                                     this.spaceColor,2);
                gg.x = x;
                gg.y = y;
                gg.type = 'slot';
                gg.setClickCallback('boardclicked');
                gg.setDblClickCallback('boarddblclicked');
                gg.setMouseOverCallback('boardMoused')
                gg.paint('');

                this.gameSlots.push(gg);
            }
        }
    }

    this.erase = function() {

    }

    this.attachSound = function(fName)
    {
        if(s instanceof gameSound)
            s.stop();

        s = new gameSound(fName);
        s.play();
    }

    this.randomSetup = function(cpu,playerNum,color,hidden) {

        if(color == 'red')prefix = 'r';
        else if(color == 'blue')prefix = 'b';

        var availPieces = new Array('1','2','3','3','4','4','4','5','5','5',
                                    '5','6','6','6','6','7','7','7','7','8',
                                    '8','8','8','8','9','9','9','9','9','9',
                                    '9','9','S','F','B','B','B','B','B','B');

        while(availPieces.length > 0)
        {
            var x = Math.floor(Math.random()*10);
            var y = Math.floor(Math.random()*10);

            if(!this.slotContainsGP(x,y) && y <= 3)
            {
                var rank = availPieces.pop();
                board.addGP(cpu, this.getSlotXY(x,y),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+rank+'.gif'),hidden),rank,true,playerNum,hidden);
            }
        }
    }

    this.setBoardCycloneDefense = function(cpu,playerNum,color,hidden) {

        if(color == 'red')prefix = 'r';
        else if(color == 'blue')prefix = 'b';

        if(playerNum == 1) yStart = 9;
        else if(playerNum == 2) yStart = 0;

        board.addGP(cpu, this.getSlotXY(0,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(1,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'6.gif'),hidden),6,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(2,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(3,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'6.gif'),hidden),6,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(4,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(5,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(6,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'7.gif'),hidden),7,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(7,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(8,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'7.gif'),hidden),7,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(9,Math.abs(yStart-0)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'4.gif'),hidden),4,true,playerNum,hidden);

        board.addGP(cpu, this.getSlotXY(0,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'5.gif'),hidden),5,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(1,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'7.gif'),hidden),7,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(2,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(3,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'6.gif'),hidden),6,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(4,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'2.gif'),hidden),2,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(5,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'8.gif'),hidden),8,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(6,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(7,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'F.gif'),hidden),'F',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(8,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(9,Math.abs(yStart-1)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'S.gif'),hidden),'S',true,playerNum,hidden);

        board.addGP(cpu, this.getSlotXY(0,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'7.gif'),hidden),7,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(1,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(2,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'8.gif'),hidden),8,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(3,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'8.gif'),hidden),8,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(4,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'5.gif'),hidden),5,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(5,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'3.gif'),hidden),3,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(6,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'8.gif'),hidden),8,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(7,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(8,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'5.gif'),hidden),5,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(9,Math.abs(yStart-2)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'1.gif'),hidden),1,true,playerNum,hidden);

        board.addGP(cpu, this.getSlotXY(0,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'B.gif'),hidden),'B',true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(1,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'3.gif'),hidden),3,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(2,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(3,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'4.gif'),hidden),4,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(4,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'6.gif'),hidden),6,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(5,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'5.gif'),hidden),5,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(6,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(7,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'8.gif'),hidden),8,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(8,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'4.gif'),hidden),4,true,playerNum,hidden);
        board.addGP(cpu, this.getSlotXY(9,Math.abs(yStart-3)),new gameGraphic(25,25,0,0,(hidden ? 'gfx/'+prefix+'.gif' : 'gfx/'+prefix+'9.gif'),hidden),9,true,playerNum,hidden);
    }

    this.setBoardTempestDefense = function(playerNum) {

    }

    this.setBoardTripleThreat = function(playerNum) {

    }

    this.setBoardScoutsGamble = function(playerNum) {

    }

    this.setBoardShorelineBluff = function(playerNum) {

    }

    this.setBoardCornerFortress = function(playerNum) {

    }

    this.setBoardShieldDefense = function(playerNum) {

    }

    this.setBoardCornerBlitz = function(playerNum) {

    }

    this.setBoardWheelOfDanger = function(playerNum) {

    }

    this.setBoardBlitzkrieg = function(playerNum) {

    }

    this.setBoardEarlyWarning = function(playerNum) {

    }

    this.setBoardManTheBarricades = function(playerNum) {

    }
}
